package com.andkrup.easygame.config {
	import flash.ui.Keyboard;	
	
	/**
	 * @author Andkrup
	 */
	public class KeycodeMap {
		private static const BACKSPACE:String = "backspace";
		private static const CAPS_LOCK:String = "capslock";
		private static const DELETE:String = "delete";
		private static const DOWN:String = "down";
		private static const END:String = "end";
		private static const ENTER:String = "enter";
		private static const ESCAPE:String = "escape";
		private static const F1:String = "f1";
		private static const F2:String = "f2";
		private static const F3:String = "f3";
		private static const F4:String = "f4";
		private static const F5:String = "f5";
		private static const F6:String = "f6";
		private static const F7:String = "f7";
		private static const F8:String = "f8";
		private static const F9:String = "f9";
		private static const F10:String = "f10";
		private static const F11:String = "f11";
		private static const F12:String = "f12";
		private static const HOME:String = "home";
		private static const INSERT:String = "insert";
		private static const LEFT:String = "left";
		private static const NUMPAD_0:String = "numpad 0";
		private static const NUMPAD_1:String = "numpad 1";
		private static const NUMPAD_2:String = "numpad 2";
		private static const NUMPAD_3:String = "numpad 3";
		private static const NUMPAD_4:String = "numpad 4";
		private static const NUMPAD_5:String = "numpad 5";
		private static const NUMPAD_6:String = "numpad 6";
		private static const NUMPAD_7:String = "numpad 7";
		private static const NUMPAD_8:String = "numpad 8";
		private static const NUMPAD_9:String = "numpad 9";
		private static const NUMPAD_ADD:String = "numpad add";
		private static const NUMPAD_DECIMAL:String = "numpad decimal";
		private static const NUMPAD_DIVIDE:String = "numpad divide";
		private static const NUMPAD_ENTER:String = "numpad enter";
		private static const NUMPAD_MULTIPLY:String = "numpad multiply";
		private static const NUMPAD_SUBTRACT:String = "numpad subtract";
		private static const PGDN:String = "page down";
		private static const PGUP:String = "page up";
		private static const RIGHT:String = "right";
		private static const SPACE:String = "space";
		private static const TAB:String = "tab";
		private static const UP:String = "up";
						
		private static const LEFT_SHIFT:String = "left shift";
		private static const RIGHT_SHIFT:String = "right shift";
		private static const LEFT_ALT:String = "left alt";
		private static const RIGHT_ALT:String = "right alt";
		private static const LEFT_CTRL:String = "left ctrl";
		private static const RIGHT_CTRL:String = "right ctrl";
		
		private static const MOUSE_1:String = "mouse1";
		private static const MOUSE_2:String = "mouse2";
		private static const MOUSE_3:String = "mouse3";
		private static const MOUSE_WHEEL_UP:String = "mouse wheel up";
		private static const MOUSE_WHEEL_DOWN:String = "mouse wheel down";
		
		public static function getKey(code:int):String{
			switch(code){
				default:
					return null;
				case Keyboard.DOWN:
					return "down";
			}
		}
		
		public static function getCode(keyName:String):int{
			if(keyName.length==1){
				return keyName.toLowerCase().charCodeAt();
			}
			else{
				switch(keyName.toLowerCase()){
					case BACKSPACE:
						return Keyboard.BACKSPACE;
					case CAPS_LOCK:
						return Keyboard.CAPS_LOCK;
					case DELETE:
						return Keyboard.DELETE;
					case DOWN:
						return Keyboard.DOWN;
					case END:
						return Keyboard.END;
					case ENTER:
						return Keyboard.ENTER;
					case ESCAPE:
						return Keyboard.ESCAPE;
					case F1:
						return Keyboard.F1;
					case F2:
						return Keyboard.F2;
					case F3:
						return Keyboard.F3;
					case F4:
						return Keyboard.F4;
					case F5:
						return Keyboard.F5;
					case F6:
						return Keyboard.F6;
					case F7:
						return Keyboard.F7;
					case F8:
						return Keyboard.F8;
					case F9:
						return Keyboard.F9;
					case F10:
						return Keyboard.F10;
					case F11:
						return Keyboard.F11;
					case F12:
						return Keyboard.F12;
					case HOME:
						return Keyboard.HOME;
					case INSERT:
						return Keyboard.INSERT;
					case LEFT:
						return Keyboard.LEFT;
					case NUMPAD_0:
						return Keyboard.NUMPAD_0;
					case NUMPAD_1:
						return Keyboard.NUMPAD_1;
					case NUMPAD_2:
						return Keyboard.NUMPAD_2;
					case NUMPAD_3:
						return Keyboard.NUMPAD_3;
					case NUMPAD_4:
						return Keyboard.NUMPAD_4;
					case NUMPAD_5:
						return Keyboard.NUMPAD_5;
					case NUMPAD_6:
						return Keyboard.NUMPAD_6;
					case NUMPAD_7:
						return Keyboard.NUMPAD_7;
					case NUMPAD_8:
						return Keyboard.NUMPAD_8;
					case NUMPAD_9:
						return Keyboard.NUMPAD_9;
					case NUMPAD_ADD:
						return Keyboard.NUMPAD_ADD;
					case NUMPAD_DECIMAL:
						return Keyboard.NUMPAD_DECIMAL;
					case NUMPAD_DIVIDE:
						return Keyboard.NUMPAD_DIVIDE;
					case NUMPAD_ENTER:
						return Keyboard.NUMPAD_ENTER;
					case NUMPAD_MULTIPLY:
						return Keyboard.NUMPAD_MULTIPLY;
					case NUMPAD_SUBTRACT:
						return Keyboard.NUMPAD_SUBTRACT;
					case PGDN:
						return Keyboard.PAGE_DOWN;
					case PGUP:
						return Keyboard.PAGE_UP;
					case RIGHT:
						return Keyboard.RIGHT;
					case SPACE:
						return Keyboard.SPACE;
					case TAB:
						return Keyboard.TAB;
					case UP:
						return Keyboard.UP;
						
					case LEFT_ALT:
						return -1;
					case RIGHT_ALT:
						return -2;
					case LEFT_SHIFT:
						return -3;
					case RIGHT_SHIFT:
						return -4;
					case LEFT_CTRL:
						return -5;
					case RIGHT_CTRL:
						return -6;
					case MOUSE_1:
						return -7;
					case MOUSE_2:
						return -8;
					case MOUSE_3:
						return -9;
					case MOUSE_WHEEL_UP:
						return -10;
					case MOUSE_WHEEL_DOWN:
						return -11;
					
					default:
						return 0;
				}
			}
			return 0;
		}
	}
}
